/**
 * ReportGear(2011)
 */
package com.reportgear.designer.gui.config.ui;

import java.awt.BasicStroke;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JComponent;
import javax.swing.JSeparator;
import javax.swing.LookAndFeel;
import javax.swing.SwingConstants;
import javax.swing.plaf.basic.BasicSeparatorUI;

/**
 * 分隔器UI
 * 
 * @version 1.0 2011-4-26
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class DottedSeparatorUI extends BasicSeparatorUI {
	protected static final Dimension vertDimension = new Dimension(0, 2);
	protected static final Dimension horzDimension = new Dimension(2, 0);

	@Override
	protected void installDefaults(JSeparator separator) {
		LookAndFeel.installColors(separator, "Separator.background", "Separator.foreground");
	}

	@Override
	public void paint(Graphics g, JComponent component) {
		drawXpSeparator(g, component);
	}

	protected void drawXpSeparator(Graphics g, JComponent component) {
		Dimension dim = component.getSize();

		g.setColor(component.getBackground());
		Graphics2D g2 = (Graphics2D) g;
		BasicStroke stroke = new BasicStroke(1.0F, 0, 0, 10.0F, new float[] { 1.0F, 1.0F, 1.0F, 1.0F }, 0.0F);
		g2.setStroke(stroke);

		if (((JSeparator) component).getOrientation() == SwingConstants.VERTICAL) {
			g2.drawLine(0, 6, 0, dim.height - 6);
		} else {
			g2.drawLine(0, 0, dim.width, 0);
		}
	}

	@Override
	public Dimension getPreferredSize(JComponent component) {
		if (((JSeparator) component).getOrientation() == SwingConstants.VERTICAL) {
			return horzDimension;
		}

		return vertDimension;
	}

	public Dimension getMinimumSize(JComponent component) {
		return getPreferredSize(component);
	}
}